package cn.hdu.liang.polymorphism;

class Characteristic {
    private String s;

    Characteristic(String s) {
        this.s = s;
        System.out.println("创建 Characteristic " + s);
    }

    protected void dispose() {
        System.out.println("销毁 Characteristic " + s);
    }
}

class Description {
    private String s;

    Description(String s) {
        this.s = s;
        System.out.println("创建 Description " + s);
    }

    protected void dispose() {
        System.out.println("销毁 Description " + s);
    }
}

class LivingCreature {
    private Characteristic p = new Characteristic("is alive");
    private Description t = new Description("basic living creature");

    LivingCreature() {
        System.out.println("LivingCreature");
    }

    protected void dispose() {
        System.out.println("销毁 LivingCreature ");
        t.dispose();
        p.dispose();
    }
}

class Animal extends LivingCreature {
    private Characteristic p = new Characteristic("has heart");
    private Description t = new Description("动物不是蔬菜");

    Animal() {
        System.out.println("Animal");
    }

    protected void dispose() {
        System.out.println("销毁 Animal ");
        t.dispose();
        p.dispose();
        super.dispose();
    }
}

class Amphibian extends Animal {
    private Characteristic p = new Characteristic("可以在水中活着");
    private Description t = new Description("水陆两栖");

    Amphibian() {
        System.out.println("Amphibian");
    }

    protected void dispose() {
        System.out.println("销毁 Amphibian ");
        t.dispose();
        p.dispose();
        super.dispose();
    }
}


public class Frog extends Amphibian {

    private Characteristic p = new Characteristic("Croaks");
    private Description t = new Description("吃bugs");

    Frog() {
        System.out.println("Frog");
    }

    protected void dispose() {
        System.out.println("销毁 Frog ");
        t.dispose();
        p.dispose();
        super.dispose();
    }

    public static void main(String[] args) {
        Frog frog = new Frog();
        System.out.println("回见了您呐");
        frog.dispose();
    }

}
